<!DOCTYPE html>
<html>
<head>
  <title>欢迎登录</title>


    <link rel="stylesheet" href="/bower_components/bootstrap/dist/css/bootstrap.css">
    <script src="/bower_components/jquery/dist/jquery.js"></script>
    <script type="text/javascript" src="/md5.js"></script>
</head>
<body>
      <div class="container" style="margin-top:180px; ">

        <div class="col-md-6 col-md-offset-3">
            <div class="panel panel-primary">
                <div class="panel-heading">码云上改3的网站</div>
                <div class="panel-body">
                   <div class="form-horizontal">
                        <div class="form-group">
                            <label for="uname" class="col-sm-2 control-label">用户名</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" name="username" id="username" placeholder="请输入用户名">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="pwd" class="col-sm-2 control-label">密码</label>
                            <div class="col-sm-10">
                                <input type="password" class="form-control" name="password" id="pwd" placeholder="请输入密码">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="pwd" class="col-sm-2 control-label">验证码</label>
                            <div class="col-sm-6">
                                <input type="text" class="form-control" name="vcode" id="vcode" placeholder="请输入验证码">
                            </div>
                            <div class="col-sm-3">
                                <img id="vcodeimg" src="/account/vcode">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10">
                                <!-- submit有一个默认的提交行为，不要加上 -->
                                <!-- <button type="submit" onclick="login()"  class="btn btn-default">登录</button> -->
                                <button id="login"  class="btn btn-default">登录</button>
                                &nbsp;&nbsp;
                                <input  id="register" type="button"  value="注册" class="btn btn-danger">
                            </div>
                        </div>
                   </div>
                </div>
            </div>
            </div>
    </div>
</body>
<script>
    //注册
    $('#register').click(()=>{
       window.location.href='/account/register'
    });
    //登录
    $("#login").click(()=> {
        let username=$("#username").val();
        let pwd=$.md5($("#pwd").val());
        let vcode=$("#vcode").val();
        $.post(
            '/account/logindata',
            {username,pwd,vcode},
            (data)=>{
                console.log(data);
            })
    });
    //点击图片刷新
    $("#vcodeimg").click(function () {
        $("#vcodeimg").attr("src","/account/vcode?id="+Math.random())
    })
</script>
</html>
